package com.woniu.controller;

import com.woniu.entity.PageResult;
import com.woniu.entity.Result;
import com.woniu.entity.dto.LogSearchDTO;
import com.woniu.pojo.Log;
import com.woniu.service.ILogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 日志控制器
 * @author tarnett
 */
@RestController
@RequestMapping("/log")
@Slf4j
@Api(tags = "日志管理")
public class LogController {

    @Autowired
    private ILogService logService;


    @ApiOperation("搜索分页")
    @PostMapping("/search")
    public Result<PageResult<Log>> listSearch(@RequestBody LogSearchDTO logSearchDTO){
        // 1. 对数据进行规则校验 TODO
        // 2. 调用业务逻辑层处理数据
        PageResult<Log> pageResult = logService.listSearch(logSearchDTO);
        // 3. 接收数据，封装响应结果
        // 4. 返回数据
        return Result.ok(pageResult);
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/{ids}")
    public Result deleteByIds(@PathVariable Long[] ids){
        Integer row = logService.deleteByIds(ids);
        return Result.commonByRow(row);
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    public Result<Log> getById(@PathVariable Long id){
        Log log = logService.getById(id);
        return Result.ok(log);
    }
}
